package com.fau.cm.action.index;

import java.util.HashMap;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;

import com.fau.cm.action.PublicAction;
import com.fau.cm.entity.MedicalAdmin;
import com.fau.cm.entity.MedicalCallHealthSymptom;
import com.opensymphony.xwork2.ModelDriven;

/**
 * @desc  会员健康档案管理Action
 * @author suny
 * @datetime 2014年10月24日,上午11:12:50
 */
@Controller
@Scope("prototype")
@ParentPackage("default")
@Namespace("/")
public class HealthSymptomAction extends PublicAction implements ModelDriven<MedicalCallHealthSymptom> {

	private static final long serialVersionUID = 5215585168823534988L;

	private MedicalCallHealthSymptom healthSymptom = new MedicalCallHealthSymptom();
	
	/**
	 * @desc 进入健康档案病例界面
	 * @return
	 * @author suny
	 * @datetime 2014年10月24日,下午2:45:46
	 */
	@Action(value = "health_init", results = {@Result(name = SUCCESS, location = "call_health_init.jsp")})
	public String init() {
		return SUCCESS;
	}
	
	/**
	 * @desc 查询健康档案病例
	 * @return
	 * @author suny
	 * @datetime 2014年10月24日,下午2:46:30
	 */
	@Action(value = "call_health_view")
	public String view() {
		HttpServletResponse response = ServletActionContext.getResponse();
		MedicalAdmin user = (MedicalAdmin) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		healthSymptom.setHospitalId(user.getEnterpriseId());
		list = this.baseAllService.getCallHealthService().findCallHealth(healthSymptom);
		formatJSON(response, list);
		return null;
	}
	
	/**
	 * @desc 打开健康档案病例添加界面
	 * @return
	 * @author suny
	 * @datetime 2014年10月24日,下午8:58:10
	 */
	@Action(value = "call_health_add",results = {@Result(name = SUCCESS,location = "call_health_add.jsp")})
	public String add(){
		return SUCCESS;
	}
	
	/**
	 * @desc 保存健康档案病例
	 * @return
	 * @author suny
	 * @datetime 2014年10月24日,下午9:00:52
	 */
	@Action(value = "call_health_save")
	public String save(){
		HttpServletResponse response = ServletActionContext.getResponse();
		MedicalAdmin admin = (MedicalAdmin) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		this.map = new HashMap<String, Object>();
		this.baseAllService.getCallHealthService().saveCallHealth(healthSymptom,admin);
		map.put("success", true);
		formatJSON(response, this.map);
		return null;
	}
	
	/**
	 * @desc 打开健康档案病例编辑界面
	 * @return
	 * @author suny
	 * @datetime 2014年10月25日,下午4:04:17
	 */
	@Action(value ="call_health_edit",results = {@Result(name = SUCCESS,location = "call_health_edit.jsp")})
	public String edit(){
		return SUCCESS;
	}
	
	/**
	 * @desc 修改健康档案病例
	 * @return
	 * @author suny
	 * @datetime 2014年10月24日,下午10:15:58
	 */
	@Action(value = "call_health_edit_save")
	public String saveEdit(){
		HttpServletResponse response = ServletActionContext.getResponse();
		this.map = new HashMap<String, Object>();
		this.baseAllService.getCallHealthService().editCallHealth(healthSymptom);
		map.put("success", true);
		formatJSON(response, this.map);
		return null;
	}
	
	/**
	 * @desc 删除健康档案病例
	 * @return
	 * @author suny
	 * @datetime 2014年10月24日,下午10:10:19
	 */
	@Action(value = "call_health_delete")
	public String del(){
		HttpServletResponse response = ServletActionContext.getResponse();
		this.map = new HashMap<String, Object>();
		this.baseAllService.getCallHealthService().delCallHealth(healthSymptom);
		map.put("success", true);
		formatJSON(response, this.map);
		return null;
	}
	
	/**
	 * @desc 验证是否允许删除基础父类
	 * @return
	 * @author suny
	 * @datetime 2014年10月25日,下午5:46:44
	 */
	@Action(value="health_judge")
	public String judge(){
		HttpServletResponse response = ServletActionContext.getResponse();
		this.map = new HashMap<String, Object>();
		boolean flag = this.baseAllService.getCallHealthService().judgeHealth(healthSymptom);
		if(flag){
			map.put("result",true);
		}else{
			map.put("result", false);
		}
		formatJSON(response, this.map);
		return null;
	}
	
	@Override
	public MedicalCallHealthSymptom getModel() {
		return healthSymptom;
	}
}
